﻿using System;
using System.Collections.Generic;
using System.Data.SQLite;
using System.Text;
using System.Windows.Forms;

namespace MyWords
{
    public class CurrentUser
    {
        public static SqLiteHelper sql;
        public static string ID;
        public string username;
        public Boolean isLogin = false;
        public static List<Word> myList = new List<Word>();

        public CurrentUser()
        {
            sql = new SqLiteHelper("data source=mywords.db");
        }

        public Boolean login(string username,string password)
        {
            SQLiteDataReader reader = sql.ReadFullTable("users");

            string temp_username;
            string temp_password;
            while (reader.Read())
            {
                temp_username = reader.GetString(reader.GetOrdinal("username"));
                temp_password = reader.GetString(reader.GetOrdinal("password"));
                
                if (temp_username == username && temp_password == password)
                {
                    this.username = temp_username;
                    isLogin = true;

                    CurrentUser.ID = reader.GetString(reader.GetOrdinal("ID"));
                    return true;
                }
            }return false;
        }

        

    }
}
